<script setup lang="ts">
import { noop } from "@/framework/util/warning";
import { useSimpleNavigation } from "@/components/framework/simple-navigation-helper";
import type { PropType } from "vue";

defineOptions({ name: "simple-navigation-link" });

const props = defineProps({
  path: { type: String as PropType<string> },
  replace: { type: Boolean as PropType<boolean> },
  back: { type: Boolean as PropType<boolean> },
});

const navigation = useSimpleNavigation();

const navigate = () => {
  if (props.back) {
    navigation.back();
    return;
  }

  if (props.replace) {
    navigation.replace(props.path!).then(noop);
  } else {
    navigation.push(props.path!).then(noop);
  }
};
</script>

<template>
  <slot :navigate="navigate" />
</template>
